package org.nfyszny.zzzs.modules.controller;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;

import org.nfyszny.zzzs.modules.entity.ZzzsBasicInfo;
import org.nfyszny.zzzs.modules.entity.ZzzsVisualInformation;
import org.nfyszny.zzzs.modules.service.IZzzsBasicInfoService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.servlet.ModelAndView;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: 基本信息
 * @Author: jeecg-boot
 * @Date: 2022-11-10
 * @Version: V1.0
 */
@Api(tags = "基本信息")
@RestController
@RequestMapping("/modules/zzzsBasicInfo")
@Slf4j
public class ZzzsBasicInfoController extends JeecgController<ZzzsBasicInfo, IZzzsBasicInfoService> {
    @Autowired
    private IZzzsBasicInfoService zzzsBasicInfoService;

    /**
     * 分页列表查询
     *
     * @param zzzsBasicInfo
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "基本信息-分页列表查询")
    @ApiOperation(value = "基本信息-分页列表查询", notes = "基本信息-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<ZzzsBasicInfo>> queryPageList(ZzzsBasicInfo zzzsBasicInfo,
                                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                      HttpServletRequest req) {
        QueryWrapper<ZzzsBasicInfo> queryWrapper = QueryGenerator.initQueryWrapper(zzzsBasicInfo, req.getParameterMap());
        Page<ZzzsBasicInfo> page = new Page<ZzzsBasicInfo>(pageNo, pageSize);
        IPage<ZzzsBasicInfo> pageList = zzzsBasicInfoService.pageList(page, queryWrapper);


        return Result.TOK(pageList);
    }

    @ApiOperation(value = "可视化信息管理-切换公司介绍显示状态", notes = "可视化信息管理-切换公司介绍显示状态")
    @GetMapping(value = "/switchIntroduceStatus")
    public Result<IPage<ZzzsVisualInformation>> switchIntroduceStatus(@RequestParam("id") String id, @RequestParam("status") Integer status) {
        zzzsBasicInfoService.updateIntroduceStatus(id, status);

        return Result.TOK();
    }

    /**
     * 添加
     *
     * @param zzzsBasicInfo
     * @return
     */
    @AutoLog(value = "基本信息-添加")
    @ApiOperation(value = "基本信息-添加", notes = "基本信息-添加")
    //@RequiresPermissions("org.nfyszny.modules:zzzs_basic_info:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody ZzzsBasicInfo zzzsBasicInfo) {
        //TODO 后期从查出登录用户属于哪个公司
        zzzsBasicInfoService.save(zzzsBasicInfo);
        return Result.TOK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param zzzsBasicInfo
     * @return
     */
    @AutoLog(value = "基本信息-编辑")
    @ApiOperation(value = "基本信息-编辑", notes = "基本信息-编辑")
    //@RequiresPermissions("org.nfyszny.modules:zzzs_basic_info:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody ZzzsBasicInfo zzzsBasicInfo) {
        zzzsBasicInfoService.updateById(zzzsBasicInfo);
        return Result.TOK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "基本信息-通过id删除")
    @ApiOperation(value = "基本信息-通过id删除", notes = "基本信息-通过id删除")
    //@RequiresPermissions("org.nfyszny.modules:zzzs_basic_info:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        zzzsBasicInfoService.removeById(id);
        return Result.TOK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "基本信息-批量删除")
    @ApiOperation(value = "基本信息-批量删除", notes = "基本信息-批量删除")
    //@RequiresPermissions("org.nfyszny.modules:zzzs_basic_info:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.zzzsBasicInfoService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.TOK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "基本信息-通过id查询")
    @ApiOperation(value = "基本信息-通过id查询", notes = "基本信息-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<ZzzsBasicInfo> queryById(@RequestParam(name = "id", required = true) String id) {
        ZzzsBasicInfo zzzsBasicInfo = zzzsBasicInfoService.getById(id);
        if (zzzsBasicInfo == null) {
            return Result.error("未找到对应数据");
        }
        return Result.TOK(zzzsBasicInfo);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param zzzsBasicInfo
     */
    //@RequiresPermissions("org.nfyszny.modules:zzzs_basic_info:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ZzzsBasicInfo zzzsBasicInfo) {
        return super.exportXls(request, zzzsBasicInfo, ZzzsBasicInfo.class, "基本信息");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    //@RequiresPermissions("zzzs_basic_info:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ZzzsBasicInfo.class);
    }

}
